<?php defined('SYSPATH') or die('No direct script access.');

	class Model_Services_Role extends Model implements Jqgrid_GridListener{
		
		public $role;
		
		public function count($criteria = false){
			return ORM::factory("role")->count_all();
		}
			
		public function getList($criteria = false){
			
			if (!$criteria)	$role_list = ORM::factory("role")->find_all()->as_array();
			else $role_list = ORM::factory("role")->order_by($criteria->sidx,$criteria->sord)->limit($criteria->limit)->find_all()->as_array();
		
			$dataset = array();
			foreach ($role_list as $role){
				$dataset[$role->id] = array($role->name, $role->description);
			}
			
			return $dataset;
		}
		
		public function get($id){
			return ORM::factory("role")->find($id);
		}
		
		public function save($id, array $data){
			$role = ($id > 0)? ORM::factory("role",$id) : ORM::factory("role");
			$role->name = $data['name'];
			$role->description = $data['description'];
			$role->save();
		        	
		    return $id;
		}
		
		public function delete($id){
			$role = ORM::factory("role",$id);
			$role->delete();
			return $id;
		}
	}
?>